﻿using DevExpress.ExpressApp.Blazor.Components.Models;
using Microsoft.AspNetCore.Components;

namespace EasyXaf.RendererTest.Sample.Blazor.Server.Editors;

public class CustomTextModel : DxComponentModelBase, IHandleValueComponentModel
{
    public string Text
    {
        get => GetPropertyValue<string>();
        set => SetPropertyValue(value);
    }

    public EventCallback<string> TextChanged
    {
        get => GetPropertyValue<EventCallback<string>>();
        set => SetPropertyValue(value);
    }

    public override Type ComponentType => typeof(CustomTextRenderer);

    public event EventHandler<HandleValueEventArgs> ValueChanged;

    object IHandleValueComponentModel.Value
    {
        get => Text;
        set => Text = value as string;
    }

    public CustomTextModel()
    {
        TextChanged = EventCallback.Factory.Create<string>(this, text =>
        {
            ValueChanged?.Invoke(this, new HandleValueEventArgs(text));
        });
    }
}
